﻿@model RentDetail
@{
    ViewBag.Title = "编辑租赁";
}
<form class="layui-form layui-form-pane" lay-filter="">
    <div class="layui-form-item">
        <label class="layui-form-label">租赁单位</label>
        <div class="layui-input-inline">
            <select id="RentDeptID" name="RentDeptID" lay-verify="required">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">租赁起始</label>
        <div class="layui-input-inline">
            <input type="text" id="BeginDate" name="BeginDate" autocomplete="off" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">租赁截止</label>
        <div class="layui-input-inline">
            <input type="text" id="EndDate" name="EndDate" autocomplete="off" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">需付金额</label>
        <div class="layui-input-inline">
            <input type="text" name="NeedPayment" autocomplete="off" class="layui-input" lay-verify="number" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">实付金额</label>
        <div class="layui-input-inline">
            <input type="text" name="ActualPayment" autocomplete="off" class="layui-input" lay-verify="number" />
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align:right;">
            <button class="layui-btn" lay-submit lay-filter="save">保存</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    layui.use(['form', 'jquery', 'laydate'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        //初始化
        laydate.render({
            elem: '#BeginDate',
            trigger: 'click',
        });
        laydate.render({
            elem: '#EndDate',
            trigger: 'click',
        });
        //获取租赁部门
        $.ajax({
            url: 'RentDept',
            data: {},
            async: false,
            success: function (res) {
                if (res.count > 0) {
                    $.each(res.data, function (i, item) {
                        $("select[name='RentDeptID']").append('<option value="' + item.ID + '">' + item.DeptName + '</option>');
                    })
                }
                form.render('select');
            }
        });
        form.val('', {
            "RentDeptID": "@Model.RentDeptID",
            "BeginDate": "@Model.BeginDate",
            "EndDate": "@Model.EndDate",
            "NeedPayment": "@Model.NeedPayment",
            "ActualPayment": "@Model.ActualPayment",
        });

        form.on("submit(save)", function (formdata) {
            formdata.field.ID = "@Model.ID";
            $.ajax({
                url: 'Edit',
                data: formdata.field,
                success: function (res) {
                    layer.alert(res.msg, function (index) {
                        layer.close(index);
                        if (res.count > 0) {
                            parent.layer.closeAll();
                        }
                    })
                }
            });
            return false;
        })
    })
</script>